package kr.hyunist.androidcomplete01saeildamil.ch08;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.OnLongClickListener;
import android.widget.*;

public class LongClickListenerEx extends Activity {
	TextView tv;
	int mCount = 0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.longclick);

		tv = (TextView) findViewById(R.id.longclicktv);

		Button db = (Button) findViewById(R.id.longclickbtn1);
		Button ib = (Button) findViewById(R.id.longclickbtn2);

		db.setOnLongClickListener(mClick);
		ib.setOnLongClickListener(mClick);
	}
	
	public void mOnClick(View v) {
		switch(v.getId()){
		case R.id.longclickbtn1:
			mCount--;
			tv.setText("" + mCount);
			break;

		case R.id.longclickbtn2:
			mCount++;
			tv.setText("" + mCount);
			break;
		}
	}
	
	OnLongClickListener mClick = new OnLongClickListener() {

		@Override
		public boolean onLongClick(View v) {
			switch (v.getId()) {
			case R.id.longclickbtn1:
				mCount = 0;
				tv.setText(String.valueOf(mCount));
				Toast.makeText(LongClickListenerEx.this, mCount + "으로 초기화 완료!", Toast.LENGTH_SHORT).show();
				break;

			case R.id.longclickbtn2:
				mCount = 10000;
				tv.setText("" + mCount);
				Toast.makeText(LongClickListenerEx.this, mCount + "으로 초기화 완료!", Toast.LENGTH_SHORT).show();
				break;
			}
			return false;
		}

	};


}
